home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_lib.arc / FLOPEN.C < prev    next >
Text File  |  1990-08-09  |  2KB  |  71 lines

  1. /**
  2. *
  3. *  Name         flopen -- Open a file
  4. *
  5. *  Synopsis     ercode = flopen(pfile,phandle,access);
  6. *               int  ercode       Returned DOS error code
  7. *               char *pfile       File path name
  8. *               int  *phandle     File handle associated with the file
  9. *               int  access       File access code
  10. *
  11. *  Description  This function opens a file with the specified file path
  12. *               name are returns a file handle with which the file may
  13. *               be accessed.  The file is opened with access rights
  14. *               specified in the access code:
  15. *
  16. *               0 - Open for reading only
  17. *               1 - Open for writing only
  18. *               2 - Open for reading and writing.
  19. *
  20. *  Returns      ercode            DOS 2.0 function error code
  21. *               phandle           Associated file handle. If an error is
  22. *                                 encountered, -1 is returned.
  23. *
  24. *  Version      1.1  (C)Copyright Blaise Computing Inc.  1983, 1984
  25. *
  26. **/
  27. #include <compiler.h>
  28.  
  29. #define utbyword(a,b)   (((a)<<8)|((b)&0x00ff))  /* a is high, b low   */
  30.  
  31. struct dreg
  32. {
  33.   unsigned ax,bx,cx,dx,si,di,ds,es;
  34. };
  35. #define DOSREG  struct dreg
  36.  
  37. int flopen(pfile,phandle,access)
  38. char *pfile;
  39. int  *phandle,access;
  40. {
  41.  
  42.     DOSREG dos_reg;
  43.     int    ercode,dos(),utinit();
  44. #if CI201A & LDATA
  45.     unsigned long ptrtoabs();
  46. #endif
  47.  
  48.     utinit(&dos_reg);                  /* Initialize registers         */
  49.     dos_reg.ax = utbyword(0x3d,access);
  50. #if LDATA
  51. #if CI201A
  52.     dos_reg.ds = (unsigned)((ptrtoabs(pfile) & 0xffff0L) >> 4L);
  53.     dos_reg.dx = (unsigned)(ptrtoabs(pfile) & 0xfL);
  54. #else
  55.     dos_reg.ds = (unsigned)(((long)(pfile) & 0xffff0L) >> 4L);
  56.     dos_reg.dx = (unsigned)((long)(pfile) & 0xfL);
  57. #endif
  58. #else
  59.     dos_reg.dx = (unsigned)pfile;
  60. #endif
  61.  
  62.     ercode     = dos(&dos_reg);
  63.     if (ercode == 0)
  64.        *phandle = dos_reg.ax;
  65.     else
  66.        *phandle = -1;
  67.  
  68.     return(ercode);
  69.  
  70. }
  71.